import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';

import 'a_test_view.dart';
import 'a_test_view2.dart';

class LifecycleDemo extends StatefulWidget {
  LifecycleDemo() {
    debugPrint("Widget 构造函数");
  }

  @override
  State<StatefulWidget> createState() {
    debugPrint("createState");
    return _LifecycleDemoState();
  }
}

class _LifecycleDemoState extends State<LifecycleDemo> {
  List<double> list = [];
  int count = 0;

  _LifecycleDemoState() {
    debugPrint("state 构造函数");
  }

  @override
  Widget build(BuildContext context) {
    debugPrint("build father");
    return Scaffold(
      backgroundColor: Colors.amber,
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[TestView(list, count), TestView2("count is $count")],
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          setState(() {
            list.add(null);
            count++;
          });
        },
        child: Icon(Icons.add),
      ),
    );
  }

  @override
  void initState() {
    debugPrint("initState");
    SchedulerBinding.instance
        .addPostFrameCallback((_) => {debugPrint("addPostFrameCallback")});
    super.initState();
  }

  @override
  void didChangeDependencies() {
    debugPrint("didChangeDependencies");
    super.didChangeDependencies();
  }

  @override
  void didUpdateWidget(LifecycleDemo oldWidget) {
    debugPrint("didUpdateWidget");
    super.didUpdateWidget(oldWidget);
  }

  @override
  void deactivate() {
    debugPrint("deactivate");
    super.deactivate();
  }

  @override
  void dispose() {
    debugPrint("dispose");
    super.dispose();
  }
}
